const input = document.querySelector('.dealt-list input')
const add = document.querySelector('.dealt-list button')
let remove =  document.querySelectorAll('.dealt-list-need button')
const dealt_list_need = document.querySelector('.dealt-list-need')
const dealt = document.querySelector('.dealt')
let index = 0
add.addEventListener('click',function() {
    if(input.value == '' && index == 0) {
        alert('没有填入代办')
        index++
    } else if (input.value == '' && index == 1) {
        alert('123')
        index++
    } else if (input.value == '' && index == 2) {
        alert('123')
        index++
    }else if (input.value == '' && index > 2) {
        alert('123')
        index++
    } else {
        index = 0
        let p = document.createElement('p')
        p.innerHTML  =  input.value
        let button = document.createElement('button')
        button.innerHTML = 'X'
        const div = document.createElement('div')
        div.className = 'dealt-list-need'
        div.append(p)
        div.append(button)
        dealt.appendChild(div)
        remove =  document.querySelectorAll('.dealt-list-need button')
        for(let i = 0; i < remove.length; i++) {
            remove[i].addEventListener('click',function() {
                this.parentNode.remove()
            })
        }
    }
    input.value = ''
    console.log(index)
})